#include <iostream>
#include <sstream>
#include <SFML/Graphics/RenderWindow.hpp>
#include <nice2d/macros.h>
#include <nice2d/scene.h>
#include <nice2d/background.h>
#include <nice2d/imagedescriptor.h>
#include <nice2d/components/imagemanager.h>
#include <nice2d/components/soundmanager.h>
#include <nice2d/widgets/desktop.h>
#include <nice2d/widgets/boxlayout.h>
#include <nice2d/widgets/button.h>
#include <nice2d/util.h>

#define SCENE_WIDTH  1152.0f
#define SCENE_HEIGHT 720.0f

class UnitScene : public Scene
{
public:
    void onInitialed()override
    {
        setSceneBox({0.0f, 0.0f, SCENE_WIDTH, SCENE_HEIGHT});
        setBackground(Background::create("./../data/images/tank/background.png", true));

        auto desktop = GET_APPLICATION_COMPONENT(Desktop);

        auto box = std::make_shared<VBoxLayout>();
        auto start = std::make_shared<Button>();
        start->setText("Start");
        start->setSize(240, 48);
        start->pressed.connect([](std::shared_ptr<BasicButton>) {
            auto soundManager = GET_APPLICATION_COMPONENT(SoundManager);
            auto playSound = std::make_shared<SoundMessagePlaySound>("./../data/sound/button.wav");
            soundManager->process(playSound);
        });

        auto exit = std::make_shared<Button>();
        exit->setText("Exit");
        exit->setSize(240, 48);
        box->addWidget(start);
        box->addWidget(exit);
        exit->pressed.connect([](std::shared_ptr<BasicButton>) {
            Application::getInstance()->exit();
        });

        auto dock = desktop->addWidget(box);
        dock->setDock(true);
        dock->setHorizontalMode(HMode_Center);
        dock->setVertical(VMode_Center);

        auto soundManager = GET_APPLICATION_COMPONENT(SoundManager);
        auto playMusic = std::make_shared<SoundMessagePlayBackgroundMusic>("./../data/sound/BGM/BGM02.WAV");
        soundManager->process(playMusic);
    }
};

DECLARE_MAIN_FUNCTION_WITH_SCENE(SCENE_WIDTH, SCENE_HEIGHT, "unit11", UnitScene)
